﻿namespace Legend.AppFabricCacheIntegration
{
    using System;
    using Caching;
    using Microsoft.ApplicationServer.Caching;

    public class AppFabricCacheAdaptor
        : ICache
    {
        private DataCache cache;

        public AppFabricCacheAdaptor(DataCache cache)
        {
            Require.ThatArgument(cache).Named("cache").IsNotNull();

            this.cache = cache;
        }

        public void Insert(string key, object value, TimeSpan timeToLive)
        {
            this.cache.Put(key, value, timeToLive);
        }

        public bool TryGetValue(string key, out object value)
        {
            value = this.cache.Get(key);

            return value != null;
        }

        public void Remove(string key)
        {
            this.cache.Remove(key);
        }
    }
}
